package com.lill.system.serivce.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.lill.system.service.ISysRedisTodayCrmService;

@Service("com.lill.system.serivce.impl.SysRedisTodayCrmServiceImpl")
public class SysRedisTodayCrmServiceImpl implements ISysRedisTodayCrmService {
	
	@Resource(name="commonRedisTemplate")
    private RedisTemplate<String, Map<String, Integer>> redisTemplate;

	@Override
	public void saveTodayCrmDataToRedis(String key, Map<String, Integer> data) {
		Calendar endDate = new GregorianCalendar();
        endDate.set(Calendar.HOUR_OF_DAY, 23);
        endDate.set(Calendar.MINUTE, 59);
        endDate.set(Calendar.SECOND, 59);
        long timeout=endDate.getTime().getTime()-new Date().getTime();
		redisTemplate.opsForValue().set(key, data, timeout, TimeUnit.SECONDS);
	}

	@Override
	public Map<String, Integer> getTodayCrmDataToRedis(String key) {
		return redisTemplate.opsForValue().get(key);
	}

}
